import sys
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("MainWindow Demo")
        self.resize(800, 600)

        button = QPushButton("close", self)
        # 连接内置信号与自定义槽
        button.clicked.connect(self.onClose)

    # 自定义槽函数
    def onClose(self):
        self.close()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()

    sys.exit(app.exec_())